package cn.tedu._05weibo.common.response;

import lombok.Getter;
import lombok.Setter;

@Setter
@Getter
public class JsonResult {
    //状态码code, 提示消息msg, 具体数据data
    private Integer code;
    private String msg;
    private Object data;

    /**
     * 1.构造方法: 针对于有数据返回的controller方法
     */
    public JsonResult(StatusCode statusCode, Object data){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
        this.data = data;
    }

    /**
     * 2.构造方法: 针对于没有数据返回的controller方法
     */
    public JsonResult(StatusCode statusCode){
        this.code = statusCode.getCode();
        this.msg = statusCode.getMsg();
    }

    public static JsonResult ok(Object data){
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

    public static JsonResult ok(){
        return ok(null);
    }
}
